package com.xxrl.shop.domain;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.hibernate.annotations.Proxy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 * @author mis
 *
 * 多对一关联商家
 * 一对多关联订单
 * 商品名
 * 二级分类
 * 价格
 * 销量
 * 浏览次数
 * 关键字 用#分割
 * 商品缩略图url
 * 商品的描述
 */
@ApiModel(description = "Product information.")
@Data
@NoArgsConstructor
@Entity
@Proxy(lazy = false)
@Table(name = "sp_product")
@EntityListeners(AuditingEntityListener.class)
public class Product implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(notes = "Unique identifier of the Product.", example = "1",
            required = true)
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "merchant_id")
    @JsonIgnore
    @ToString.Exclude
    @EqualsAndHashCode.Exclude
    @JSONField(serialize = false)
    private Merchant merchant;

    @OneToMany(mappedBy = "product")
    @JsonIgnore
    @ToString.Exclude
    @EqualsAndHashCode.Exclude
    @JSONField(serialize = false)
    private Set<Order> orders = new HashSet<>();

    private String name;
    private String mainType;
    private String subType;
    private Integer prices;
    private Integer sellCount;
    private Integer viewCount;
    private String keywords;
    private String image;

    @Column(length = 1024)
    private String content;

    @CreatedDate
    private Long createTime;

    @LastModifiedDate
    private Long lastModifiedTime;
    
    public Product(Long id) {
        this.id = id;
    }
}
